package cn.wxl.plugindemo

import org.gradle.api.Plugin
import org.gradle.api.Project

class MyPlugin : Plugin<Project> {

    override fun apply(project: Project) {

        LogUtil.project = project

        project.extensions.create("WxlSrcExt", SrcExt::class.java);

        project.afterEvaluate {
            //在gradle 构建完之后执行
            LogUtil.error("afterEvaluate---: ");
            test(project)
        }

        project.task("wxlppp") {

            LogUtil.error("task---: ");

//            LogUtil.error("dellogExtension: " + project.dellogExtension);

        }
    }

    private fun test(project: Project) {
        //在gradle 构建完之后执行
        val projectDir = project.projectDir.toString();
        val extension = project.extensions.findByType(SrcExt::class.java)
        LogUtil.error("projectDir: $projectDir");
        LogUtil.error("WxlSrcExt: $extension");
        AddCodeUtil.addCode(projectDir, extension)
    }

}